/*
#include <jni.h>
#include <string>
#include "LyTool.h"
#include "LyLogPrint.h"
#include "LogWriter.h"
//
//MemoryFile *memoryFile;
//bool isInited = false;

//extern "C"
//JNIEXPORT void JNICALL
//Java_com_szlanyou_lylog_LyLogSaveTool_init(JNIEnv *env, jobject thiz, jstring file_dir) {
//    if (isInited) {
//        LOGD("isInited is true，无需重复初始化");
//        return;
//    }
//
//    const char *fileDir = env->GetStringUTFChars(file_dir, JNI_FALSE);
//    memoryFile = new MemoryFile(*fileDir);
//    // 释放内存
//    env->ReleaseStringUTFChars(file_dir, fileDir);
//    isInited = true;
//    LOGD("初始化完成!");
//}

//extern "C"
//JNIEXPORT void JNICALL
//Java_com_szlanyou_lylog_LyLogSaveTool_writeLog(JNIEnv *env, jobject thiz, jstring message) {
//    const char *buffer_message = env->GetStringUTFChars(message, JNI_FALSE);
//    memoryFile->writeLog(buffer_message);
//}


LogWriter *logWriter;
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_szlanyou_lylog_tool_LyLogSaveTool_nativeInit(JNIEnv *env,
                                                      jobject thiz,
                                                      jstring basic_info,
                                                      jstring dir, jstring key) {
    logWriter = new LogWriter();
    std::string basicInfo;
    if (basic_info != nullptr) {
        basicInfo = jstring2string(env, basic_info);
        LOGD("basicInfo=%s", basicInfo.c_str());
        env->DeleteLocalRef(basic_info);
    }

    std::string logDir;
    if (dir != nullptr) {
        logDir = jstring2string(env, dir);
        std::string logDir2 = jstringToStdString(env, dir);

        LOGD("地址logDir=%s", logDir.c_str());
        LOGD("地址logDir2=%s", logDir2.c_str());
        env->DeleteLocalRef(dir);
    }

    std::string encryptKey;
    if (key != nullptr) {
        encryptKey = jstring2string(env, key);
        LOGD("encryptKey=%s", encryptKey.c_str());
        env->DeleteLocalRef(key);
    }

    ErrInfo *errInfo = logWriter->init(env, basicInfo, logDir, encryptKey);
    jboolean initSuccess = errInfo == nullptr;
    if (!initSuccess) {
        showLog("初始化失败,%d,%s", errInfo->errCode, errInfo->errMsg);
        delete errInfo;
    }
    return initSuccess;
}



extern "C"
JNIEXPORT jboolean JNICALL
Java_com_szlanyou_lylog_tool_LyLogSaveTool_nativeWrite(JNIEnv *env, jobject thiz,
                                                       jstring msg_content ) {

    if (msg_content == nullptr) {
        return false;
    }

    const char *msg = env->GetStringUTFChars(msg_content, JNI_FALSE);
    ErrInfo *errInfo = logWriter->writeLog(env, msg   );
    env->ReleaseStringUTFChars(msg_content, msg);
    jboolean writeSuccess = errInfo == nullptr;
    if (!writeSuccess) {
        showLog("写入失败,%d,%s", errInfo->errCode, errInfo->errMsg);
        delete errInfo;
    }

    return writeSuccess;
}

*/
